<script language="javascript" runat="server">

function checkQoutas()
{
	interview.qoutaReset();
	var qouta = new String(interview.getNextQouta());
	var qoutaName = new String("");
	var qoutasAdded = new String(Session("user_qoutas_added"));
	while(qouta.length != 0)
	{
		qoutaName = String(interview.getQoutaName());
		if(qoutasAdded.indexOf("|"+qoutaName+"|") < 0)
		{
			var qoutaType = new String(qouta.substr(0,1));
			var expression = new String(qouta.substring(1,qouta.length));
			if(qoutaType=="A") // only Answer qoutas are handled here..
			{
				if(eval(String(expression)))
				{
					qoutasAdded += "|"+qoutaName+"|";
					Session("user_qoutas_added") = qoutasAdded;
					// if Qouta overflow, function returns false
					if(!interview.increaseCurrentQouta(interviewee.intervieweeID))
					{
						Response.Redirect("?screenType=qoutaOverflow");
						Response.End();
					}
				}
			}
			else if(qoutaType=="F") // Check Filters
			{
				if(eval(String(expression)))
				{
					interviewee.SetAsFiltered(String(Session("user_workingSurvey")), String(qoutaName), getRemoteUserName());
					Response.Redirect("?screenType=filtered");
					Response.End();
				}
			}
		}
		qouta = String(interview.getNextQouta());
	}
}


function checkAndIncreaseExtraFieldQoutas()
{
	var extraFieldQoutaCount = interview.qoutaCount;
	for(var qIndex = 0; qIndex < extraFieldQoutaCount; qIndex++)
	{
		var qouta = interview.QoutaByIndex(qIndex);
		if(qouta.qoutaType=="EXTRA")
		{
			if(interviewee.extras(qouta.qoutaColumn)==qouta.qoutaValue)
			{
				interview.increaseExtraFieldQouta(qouta.qoutaName, interviewee.intervieweeID);
			}
		}
		if(qouta.qoutaType=="ANSWER")
		{
		    if(eval(qouta.QoutaExpression))
		    {
		        interview.increaseAnswerQouta(qouta.qoutaName, interviewee.intervieweeID)
	}
		}
	}
	interview.increaseTotalQouta(interviewee.intervieweeID);
}

function SETASFILTERED(qoutaName)
{
	interviewee.SetAsFiltered(String(Session("user_workingSurvey")), String(qoutaName), getRemoteUserName());
	Response.Redirect("?screenType=filtered");
	Response.End();
}

</script>